/***************************************************************************
 *   Copyright (C) 2008 by Marco Gulino   *
 *   marco.gulino@gmail.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA            *
 ***************************************************************************/
#include "systemintegrationtest.h"
#include "assertionUtils.h"

#include <QCryptographicHash>
#include <QTime>
#include <QDebug>

const long SystemIntegrationTest::MB(1024 * 1024);

void SystemIntegrationTest::testHashingTime()
{
    QString buffer;
    for(int i=0; i< 10*MB; i++) {
        buffer.append( (char) qrand() );
    }
    qDebug() << "String filled, starting timer" << endl;
    int md4time, md5time, sha1time;
    QTime aTime;
    aTime.start();
    QCryptographicHash::hash(buffer.toAscii() , QCryptographicHash::Md4);
    qDebug() << "md4 time: " << (md4time=aTime.restart() ) << ";\n";
    QCryptographicHash::hash(buffer.toAscii() , QCryptographicHash::Md5);
    qDebug() << "md5 time: " << (md5time=aTime.restart() ) << ";\n";
    QCryptographicHash::hash(buffer.toAscii() , QCryptographicHash::Sha1);
    qDebug() << "sha1 time: " << (sha1time=aTime.restart() ) << ";\n";
    QVERIFY( md4time < md5time);
    QVERIFY( md5time < sha1time);
}
